import axios from "axios";

axios.defaults.withCredentials = true;// 允许跨域携带cookie
axios.interceptors.request.use((config)=>{
    let token = sessionStorage.getItem("token");
    if(token){
        config.headers['usertoken']=token;
    }
    return config
})

axios.interceptors.response.use((config)=>{

    if(config.data === 'toLogin'){
        sessionStorage.removeItem("token")
        location.href="/Login"
        return
    }
    return config
})
export default axios;